package com.user.controller;

import com.user.client.ProductClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(value = "用户测试模块")
@RequestMapping("user")
public class UserController {
    @Value("${server.port}")
    private int port;
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    ProductClient productClient;

    @ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
    @GetMapping("findAll")
    public Map<String, Object> findAll(){
        //1.使用restTemplate调用商品服务
        Map<String,Object> forObject = restTemplate.getForObject("http://localhost:8888/product/findAll",
                Map.class);
        return forObject;
    }
    @GetMapping("/user/findAll1")
    public Map<String, Object> findAll1(){
        //1.使用restTemplate调用商品服务
        Map<String,Object> forObject = productClient.findAll();
        return forObject;
    }
    @GetMapping("/user/gatewaytest")
    public Map<String, Object> gatewaytest(){
        //1.使用restTemplate调用商品服务
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("服务器调用成功，当前端口",port);
        return resultMap;
    }

}
